package 牛客题霸;

import java.util.Stack;

public class 判断一个链表是否为回文结构 {

    public boolean isPail(ListNode head) {
        if (head == null) {
            return false;
        }

        if (head.next == null) {
            return true;
        }

        Stack<ListNode> stack = new Stack<>();
        ListNode cur = head;
        while (cur != null) {
            stack.push(cur);
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            if (stack.pop().val != cur.val) {
                return false;
            }
            cur = cur.next;
        }

        return true;
    }

    public static void main(String[] args) {

    }

    public static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
}
